Property settings (for example):
Device : PWMMC
Mode : complementary
Align : center-aligned mode
Top-Side PWM Polarity : Positive
Bottom-Side PWM Polarity : Positive
Reload : every 8 PWM cycle
Dead time : 0 us
Correction method : method 1
Fault modes 0-3 : Automatic
Enabled in init code : no
Events enabled in init. code : no
High speed mode : This bean is enabled
MAIN.C
/* Main method sets the period register to maximum
and the duty to minimum value.
After setting this properties will be enabled
the PWMMC device and the events. */
void main(void)
{
word i;
PWMC1_SetPeriod(0x1234); // set period register
// to 0x1234 value
for (i=0; i<5; i+=2) {
PWMC1_SetDuty(i, 0x00); // set init. duty register to 0
// for each pair
}
PWMC1_SetPrescaler(3); // set prescaler of the PWMMC
PWMC1_Load(); // accept new values
PWMC1_EnableEvent(); // enable events
PWMC1_Enable(); // enable PWMMC
for(;;);
}
EVENTS.C
/* The PWMC1_OnReload method increase duty of each
complementary pair of PWMMC */
void PWMC1_OnReload(void)
{
for (i=1; i<6; i+=2) {
PWMC1_SetDuty(i,duty); // increase duty for each pair
/* May be used the following methods */
/* Setting duty by percent value: duty = 0 .. 100 */
// PWMC1_SetDutyPercent(i, duty);
/* Only for CPUs HCS12 and 56800 */
/* Setting duty by ratio value: duty = 0 .. 65535 */
// PWMC1_SetRatio16(i, duty);
/* Setting duty by ratio value: duty = 0 .. 32767 */
// PWMC1_SetRatio15(i, duty);
}
PWMC1_Load(); // accept new duties
duty++;
}
/* The PWMC1_OnFault method disable the PWMMC */
void PWMC1_OnFault(void)
{
PWMC1_Disable(); // stop PWMMC due to
// fault condition
}
For more about typical usage of the bean code please refer to the page Bean Code Typical Usage.